﻿using KaytechSoftware.Cms.App.Areas.Admin.Interfaces;
using KaytechSoftware.Cms.App.Areas.Admin.Models.Base;
using KaytechSoftware.Cms.App.Common;
using KaytechSoftware.Cms.Services.Dto;

namespace KaytechSoftware.Cms.App.Areas.Admin.Models.Entities
{
    public class NewsModel : GridEntityModel, IGridEntityModel<NewsDto>
    {
        [Id]
        [Label(ResourceKey = "Id")]
        [Renderer(Type = RendererType.Hidden)]
        public long Id { get; set; }

        [Label(ResourceKey = "Title")]
        [Renderer(Type = RendererType.TextBox)]
        public string Title { get; set; }

        [Label(ResourceKey = "Body")]
        [Renderer(Type = RendererType.TextArea)]
        public string Body { get; set; }

        [Label(ResourceKey = "Page")]
        [Renderer(Type = RendererType.DropDown, UseCollection = CollectionKey.Page)]
        [SkipInGrid]
        public long PageId { get; set; }

        [Label(ResourceKey = "Page")]
        [Renderer(Type = RendererType.TextBox)]
        [SkipInDetails]
        public string Page { get; set; }

        public GridEntityModel FromDto(NewsDto dto)
        {
            Id = dto.Id;
            Title = dto.Title;
            Body = dto.Body;
            PageId = dto.PageId;
            Page = dto.PageTitle;
            return this;
        }

        public NewsDto ToDto()
        {
            return new NewsDto
                {
                    Id = Id,
                    Title = Title,
                    Body = Body,
                    PageId = PageId,
                    PageTitle = Page
                };
        }
    }
}